package com.stock.demo.function.trade.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.stock.demo.R;
import com.stock.demo.framework.ui.view.StockBaseDialog;


/**
 * Created by XuZhaoyu on 2017/4/17.
 */

public class BottomSelectDialog extends StockBaseDialog {
    private String msg1;
    private String msg2;
    private OnItemClickListener mClickListener;

    public BottomSelectDialog(@NonNull Context context, String msg1, String msg2, OnItemClickListener mClickListener) {
        super(context, R.style.loading_dialog);
        this.msg1 = msg1;
        this.msg2 = msg2;
        this.mClickListener = mClickListener;
    }

    @Override
    public void initWindow(WindowManager windowManager, Window window) {
        window.setGravity(Gravity.BOTTOM);
        int width = windowManager.getDefaultDisplay().getWidth();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
        attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(attributes);
    }

    @Override
    public boolean setDialogCancelable() {
        return false;
    }

    @Override
    public View setDialogView() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_bottom_select, null);
        TextView item1 = (TextView) view.findViewById(R.id.tv_item1);
        TextView item2 = (TextView) view.findViewById(R.id.tv_item2);
        TextView cancel = (TextView) view.findViewById(R.id.tv_cancel);
        item1.setText(msg1);
        item2.setText(msg2);
        cancel.setText("取消");
        if (null != mClickListener) {
            item1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mClickListener.item1Click();
                    BottomSelectDialog.this.dismiss();
                }
            });
            item2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mClickListener.item2Click();
                    BottomSelectDialog.this.dismiss();
                }
            });
        }
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BottomSelectDialog.this.dismiss();
            }
        });
        return view;
    }

    public interface OnItemClickListener {
        void item1Click();

        void item2Click();
    }

}
